__author__ = 'nvsmirnov'
# -*- coding: utf-8 -*-

import unittest
from Framework.DataClasses.CUser import *
from Framework.PageClasses.CpDefault import CpDefault
from Framework.PageClasses.CpLogin import CpLogin
from Framework.PageClasses.CpAuctionRequest import CpAuctionRequest
from Framework.PageClasses.CpAuctionRequestEdit import CpAuctionRequestEdit
from Framework.PageClasses.CpAuctionRequestDelete import CpAuctionRequestDelete
from Framework.DataClasses.DatabaseData import createDatabaseData
from Tests._tcBase import _tcBase

class AuctionRequest(unittest.TestCase, _tcBase):
    """
    Класс тестирует подачу заявки на участие в аукцион, изменение заявки и отзыв заявки
    """
    auction = createDatabaseData()
    auction_id = auction.insertAuction2_3_4()
    print "Получили id добавленного аукциона: ", auction_id

    def setUp(self):
        _tcBase.setUpFireFox(self)

    def tearDown(self):
        _tcBase.tearDown(self)
        #_tcBase.clear_ie_cache(self)

    def test_1_AuctionRequest(self, id = auction_id):
        #Заходим в систему под пользователем с ролью Поставщик
        pageLogin = CpLogin(self.driver)
        pageLogin.open(self.driver, pageLogin.url)
        pageLogin.loginAs(user2)

        pageAuctionReuqest = CpAuctionRequest(self.driver)
        pageAuctionReuqest.openAuction(id)
        pageAuctionReuqest.fillForm()
        pageAuctionReuqest.submitForm()

        pageDefault = CpDefault(self.driver)
        pageDefault.LogOut()

    def test_2_AuctionRequestEdit(self, id = auction_id):
        #Заходим в систему под пользователем с ролью Поставщик
        pageLogin = CpLogin(self.driver)
        pageLogin.open(self.driver, pageLogin.url)
        pageLogin.loginAs(user2)

        auctionRequestEdit = CpAuctionRequestEdit(self.driver)
        auctionRequestEdit.openAuction(id)
        auctionRequestEdit.fillForm()
        auctionRequestEdit.submitForm()

        defaultForm = CpDefault(self.driver)
        defaultForm.LogOut()

    def test_3_AuctionRequestDelete(self, id = auction_id):
        #Заходим в систему под пользователем с ролью Поставщик
        pageLogin = CpLogin(self.driver)
        pageLogin.open(self.driver, pageLogin.url)
        pageLogin.loginAs(user2)

        pageAuctionRequestDelete =  CpAuctionRequestDelete(self.driver)
        pageAuctionRequestDelete.openAuction(id)
        pageAuctionRequestDelete.fillForm()
        pageAuctionRequestDelete.submitForm()

        defaultForm = CpDefault(self.driver)
        defaultForm.LogOut()

    def test_4_delete_auction(self, id = auction_id):
        delete_auction = createDatabaseData()
        delete_auction.delete_auction(delete_id = id)



if __name__ == '__main__':
    unittest.main()